package com.ruoyi.web.controller.Base;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.Ability_BlackListInfor;
import com.ruoyi.domain.Ability_ServiceInfor;
import com.ruoyi.service.Ability_BlackListInforService;
import com.ruoyi.service.impl.Ability_BlackListInforServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/black")
public class BlaclListController extends BaseController {
    @Autowired
    Ability_BlackListInforService ability_BlackListInforService;

    @GetMapping("/list")
    public TableDataInfo getList(@RequestParam(required = false,value = "sername") String ip,
                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, // 添加默认值可选
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
    {
        startPage();
        Ability_BlackListInfor ability_BlackListInfor=new Ability_BlackListInfor();
        ability_BlackListInfor.setIp(ip);
        return getDataTable(ability_BlackListInforService.selectAbility_BlackListInforList(ability_BlackListInfor));
    }
@PostMapping("/add")
    public AjaxResult insertBlackListInfor(@RequestBody Ability_BlackListInfor ability_BlackListInfor){

        int k=ability_BlackListInforService.insertAbility_BlackListInfor(ability_BlackListInfor);
        if(k==1){
            return AjaxResult.success("添加成功");
        }else if (k==-101){
            return AjaxResult.error("输入错误的IP地址格式");
        }else if(k==-102){
            return AjaxResult.error("该IP地址已经被拉黑，请勿重乎添加");
    }else {
            return AjaxResult.error("服务器发生错误");
        }
    }
    @GetMapping("/del")
    public  AjaxResult deleteBlackListInfor(@RequestParam(value = "id") Integer id){
        int k=ability_BlackListInforService.deleteAbility_BlackListInforById(id);
        if(k==1){
            return AjaxResult.success("删除成功");
        }else {
            return AjaxResult.error("服务器发生错误,删除失败");
        }
    }
}
